package com.zcdyy.rentalofhouse.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zcdyy.rentalofhouse.R;
import com.zcdyy.rentalofhouse.bean.AllRental;
import com.zcdyy.rentalofhouse.utils.BaseTranslucentActivity;
import com.zcdyy.rentalofhouse.utils.ImageLoaderUtils;

/**
 * 整租
 */
public class AllRentalDetailActivity extends BaseTranslucentActivity implements View.OnClickListener {
    private TextView tvTitle,right;
    private ImageView head;
    private TextView name;
    private TextView price;
    private TextView payStyle;
    private TextView tingshi;
    private TextView mianji;
    private TextView xiaoqu;
    private TextView address;
    private TextView desc;
    private TextView phone;
    private TextView person;
    private LinearLayout ll_phone;
    private LinearLayout ll_sms;
    private RelativeLayout rl_right;
    private AllRental allRental;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_rental);
        initView();
        bind();
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        right.setText("留言");
        right.setVisibility(View.VISIBLE);
        if (intent != null) {
            Bundle bundle = intent.getBundleExtra("bundle");
            tvTitle.setText("整租详情");
            allRental = (AllRental) bundle.getSerializable("allRental");
            ImageLoaderUtils.loadImage(this, allRental.getPic().getFileUrl(), head);
            name.setText(allRental.getTitle());
            price.setText(allRental.getPrice());
            payStyle.setText(allRental.getPayStyle());
            tingshi.setText(allRental.getShi() + "室" + allRental.getTing() + "厅" + allRental.getWei() + "卫");
            mianji.setText(allRental.getMianji());
            xiaoqu.setText(allRental.getVillage());
            address.setText(allRental.getAddress());
            desc.setText(allRental.getDesc());
            person.setText(allRental.getPerson());
            phone.setText(allRental.getPhone());
        }

    }

    private void bind() {
        ll_phone.setOnClickListener(this);
        ll_sms.setOnClickListener(this);
        rl_right.setOnClickListener(this);
    }

    private void initView() {
        rl_right = (RelativeLayout) findViewById(R.id.top_rl_right);
        tvTitle = (TextView) findViewById(R.id.top_tv_title);
        right = (TextView) findViewById(R.id.top_tv_right);
        head = (ImageView) findViewById(R.id.iv_house_pic);
        name = (TextView) findViewById(R.id.tv_house_name);
        price = (TextView) findViewById(R.id.tv_house_money);
        payStyle = (TextView) findViewById(R.id.tv_house_rlue);
        tingshi = (TextView) findViewById(R.id.tv_tingshi_show);
        mianji = (TextView) findViewById(R.id.tv_house_mianji_show);
        xiaoqu = (TextView) findViewById(R.id.tv_house_xiaoqu_show);
        address = (TextView) findViewById(R.id.tv_house_address_content);
        desc = (TextView) findViewById(R.id.tv_house_desc);
        phone = (TextView) findViewById(R.id.phone);
        person = (TextView) findViewById(R.id.person);
        ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        ll_sms = (LinearLayout) findViewById(R.id.ll_sms);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.ll_phone:
                Intent intent = new Intent();
                intent.setAction("android.intent.action.CALL");
                intent.setData(Uri.parse("tel:"+ phone.getText().toString()));//mobile为你要拨打的电话号码，模拟器中为模拟器编号也可
                startActivity(intent);

                break;
            case  R.id.ll_sms:
                Uri smsToUri = Uri.parse("smsto:"+phone.getText().toString());
                Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
                mIntent.putExtra("sms_body", "您好，我对你的房屋很感兴趣。方便联系一下么？");
                startActivity( mIntent );
                break;
            case R.id.top_rl_right:
                Intent intent1 = new Intent(AllRentalDetailActivity.this,CommentActivity.class);
                intent1.putExtra("id",allRental.getObjectId());
                startActivity(intent1);
                break;
        }
    }
}
